package com.marvels.approve.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.manager.dto.CaseManagerProductTypeDTO;
import com.marvels.approve.manager.service.ICaseManagerProductTypeService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**查询产品流程查询
 * @author 何杰
 * 2018年4月10日
 */
@RestController
@RequestMapping("approve/manager_pt/service")
public class CaseManagerProductTypeServiceController {
	@Autowired
	private ICaseManagerProductTypeService caseManagerProductTypeService ;
	/**查询产品流程查询
	 * @param ptDto
	 * @return
	 */
	@RequestMapping("show")
	@ResponseBody
	public MarvelsResultDTO showCMPT(@RequestBody(required=false) CaseManagerProductTypeDTO ptDto){
//		MarvelsResultDTO.getFailResult(MarvelsErrorCode.FAIL.getValue(), "调用服务失败，角色代码已经存在")
		try {
			List datas = caseManagerProductTypeService.findCaseManagerProductTypes(ptDto);
			MarvelsLogUtil.getInstance().info("init......"+datas);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), datas);
		} catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error("init...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("init...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	/**通过ID查询
	 * @param ptEn
	 * @return
	 */
	@RequestMapping("id")
	@ResponseBody
	public MarvelsResultDTO showCMPTById(@RequestBody(required=false) CaseManagerProductTypeDTO ptEn){
		try {
			ptEn = caseManagerProductTypeService.findCaseManagerProductTypeById(ptEn);
			MarvelsLogUtil.getInstance().info("error......"+ptEn);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), ptEn);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**新增产品流程
	 * @param ptEntity
	 * @return
	 */
	@RequestMapping("add")
	@ResponseBody
	public MarvelsResultDTO addCMPT(@RequestBody CaseManagerProductTypeDTO ptEntity){
		try {
			ptEntity = caseManagerProductTypeService.saveCaseManagerProductType(ptEntity);
			MarvelsLogUtil.getInstance().info("error......"+ptEntity);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), ptEntity);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	} 
	
	/**新增产品流程
	 * @param ptEntity
	 * @return
	 */
	@RequestMapping("modify")
	@ResponseBody
	public MarvelsResultDTO modifyCMPT(@RequestBody CaseManagerProductTypeDTO ptEntity){
		try {
			ptEntity = caseManagerProductTypeService.saveCaseManagerProductType(ptEntity);
			MarvelsLogUtil.getInstance().info("info......"+ptEntity);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), ptEntity);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	} 
}
